from pms.common.views import PostFormula
from user.models import User
from technology.models import Technology
from user.utils.technology import user_delete_technology


class API(PostFormula):

    def handle(self, req):
        uid = req['uid']
        tid = req['tid']
        user = User.objects.get(id=uid)
        if user == self.user:
            self.assert_one_of_permissions([5, 6])
        else:
            self.assert_permissions([6])
        deleted_tid = user_delete_technology(user, Technology.objects.get(id=tid))
        return self.success_respond({
            'tid': deleted_tid
        })
